﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for HocVien_LopDAL
/// </summary>
public class HocVien_LopDAL
{
    public static object IsNull(object checkValue, object replaceValue)
    {
        if (checkValue.Equals(System.DBNull.Value) || checkValue == null)
            return replaceValue;
        return checkValue;
    }

    public static List<HocVien_LopINFO> listAll()
    {
        string sql = "select * from HOCVIEN_LOP";
        SqlDataReader dr = SQLHelper.ExecuteReader(Conn.ConnectionString, CommandType.Text, sql, null);
        return SQLHelper.SetListObjects<HocVien_LopINFO>(dr);
    }

    public static HocVien_LopINFO GetInfo(int mahocvien, int malop)
    {
        string sql = "select * from HOCVIEN_LOP where MaHV=" + mahocvien + " AND MaLop =" + malop + "";
        SqlDataReader dr = SQLHelper.ExecuteReader(Conn.ConnectionString, CommandType.Text, sql, null);
        return SQLHelper.SetObject<HocVien_LopINFO>(dr);
    }

    public static int Insert(HocVien_LopINFO obj)
    {
        string sql = "INSERT INTO HOCVIEN_LOP (MaHV,MaLop,SoBuoiNghi,TinhTrang) VALUES (" + obj.MaHV + ",'" + obj.MaLop + "'," + obj.SoBuoiNghi + " ,'" + obj.TinhTrang + "')";
        return SQLHelper.ExecuteNonQuery(Conn.ConnectionString, CommandType.Text, sql, null);
    }

    public static int Update(HocVien_LopINFO obj)
    {
        string sql = "Update HOCVIEN_LOP set SoBuoiNghi=" + obj.SoBuoiNghi + ",TinhTrang=" + obj.TinhTrang + " Where MaHV=" + obj.MaHV + " AND MaLop =" + obj.MaLop;
        return SQLHelper.ExecuteNonQuery(Conn.ConnectionString, CommandType.Text, sql, null);
    }

    public static int Delete(int mahocvien, int malop)
    {
        string sql = "Delete from HOCVIEN_LOP where MaHV =" + mahocvien + " and MaLop =" + malop + "";
        return SQLHelper.ExecuteNonQuery(Conn.ConnectionString, CommandType.Text, sql, null);
    }

}